<!DOCTYPE html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.3" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon.png?v=5.1.3">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.png?v=5.1.3">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.png?v=5.1.3">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.3" color="#222">





  <meta name="keywords" content="DNS," />





  <link rel="alternate" href="/atom.xml" title="大牙的杂货铺" type="application/atom+xml" />






<meta name="description" content="DNS服务DNS基础DNS（Domain Name System，域名系统），在Internet上作为域名与IP地址相互映射的一个分布式数据库，能够使用户更方便的使用域名访问互联网，而不用去记住只能被机器识别的IP地址。域名(FQDN)和IP地址之间的转换工作称为域名解析（或主机名解析）。  ICANN  ICANN，">
<meta name="keywords" content="DNS">
<meta property="og:type" content="article">
<meta property="og:title" content="DNS服务">
<meta property="og:url" content="http://linuxgeeks.github.io/2016/02/05/2016-02-05-123530-DNS服务/index.html">
<meta property="og:site_name" content="大牙的杂货铺">
<meta property="og:description" content="DNS服务DNS基础DNS（Domain Name System，域名系统），在Internet上作为域名与IP地址相互映射的一个分布式数据库，能够使用户更方便的使用域名访问互联网，而不用去记住只能被机器识别的IP地址。域名(FQDN)和IP地址之间的转换工作称为域名解析（或主机名解析）。  ICANN  ICANN，全称Internet Corporation for Assigned Name">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://ohlli9uc9.bkt.clouddn.com/dns1.jpg">
<meta property="og:image" content="http://ohlli9uc9.bkt.clouddn.com/dns2.jpg">
<meta property="og:image" content="http://ohlli9uc9.bkt.clouddn.com/dns3.png">
<meta property="og:image" content="http://ohlli9uc9.bkt.clouddn.com/dns4.png">
<meta property="og:image" content="http://ohlli9uc9.bkt.clouddn.com/dns5.png">
<meta property="og:image" content="http://ohlli9uc9.bkt.clouddn.com/dns6.png">
<meta property="og:updated_time" content="2018-01-30T14:14:02.969Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="DNS服务">
<meta name="twitter:description" content="DNS服务DNS基础DNS（Domain Name System，域名系统），在Internet上作为域名与IP地址相互映射的一个分布式数据库，能够使用户更方便的使用域名访问互联网，而不用去记住只能被机器识别的IP地址。域名(FQDN)和IP地址之间的转换工作称为域名解析（或主机名解析）。  ICANN  ICANN，全称Internet Corporation for Assigned Name">
<meta name="twitter:image" content="http://ohlli9uc9.bkt.clouddn.com/dns1.jpg">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    version: '5.1.3',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":true},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://linuxgeeks.github.io/2016/02/05/2016-02-05-123530-DNS服务/"/>





  <title>DNS服务 | 大牙的杂货铺</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>
	
	<a href="https://github.com/mengdaya"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">大牙的杂货铺</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-commonweal">
          <a href="/404/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-heartbeat"></i> <br />
            
            公益404
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://linuxgeeks.github.io/2016/02/05/2016-02-05-123530-DNS服务/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="孟庆宇">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="大牙的杂货铺">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">DNS服务</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2016-02-05T12:35:30+08:00">
                2016-02-05
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Services/" itemprop="url" rel="index">
                    <span itemprop="name">Services</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv"><i class="fa fa-file-o"> 本文总阅读量</i>
            <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>次
            </span>
          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  6,881
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  31
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h3 id="DNS服务"><a href="#DNS服务" class="headerlink" title="DNS服务"></a>DNS服务</h3><h4 id="DNS基础"><a href="#DNS基础" class="headerlink" title="DNS基础"></a>DNS基础</h4><p>DNS（Domain Name System，域名系统），在Internet上作为域名与IP地址相互映射的一个分布式数据库，能够使用户更方便的使用域名访问互联网，而不用去记住只能被机器识别的IP地址。域名(FQDN)和IP地址之间的转换工作称为域名解析（或主机名解析）。</p>
<ul>
<li>ICANN</li>
</ul>
<p>ICANN，全称Internet Corporation for Assigned Names and Numbers(互联网名称与数字地址分配机构)，是一个非盈利性的国际组织，负责互联网协议(IP)地址的空间分配，协议标示符的指派，通用顶级域名 (gTLD)以及国家和地区顶级域名(ccTLD)系统的管理，以及根服务器系统的管理。官方网址是：<a href="http://www.icann.org" target="_blank" rel="noopener">http://www.icann.org</a> </p>
<p>ICANN的作用：负责协调管理DNS各技术要素以确保普遍可解析性，使所有的互联网用户都能够找到有效的地址。它是通过监督互联网运作当中独特的技术标示符的分配以及顶级域名的授权来做到这点的。</p>
<ul>
<li>hosts映射</li>
</ul>
<p>早期，名字到地址的转换过程十分简单。每台计算机保存一个hosts文件，里面列出所有计算机名字和对应的IP地址，然后定期从一个维护此文件的站点更新里面的记录。当我们访问某个计算机名字时，先在hosts文件找到对应的IP，然后就可以建立连接。</p>
<p>随着网络规模的扩大，这种方法渐渐吃不消了。主要有以下三个原因：</p>
<blockquote>
<ul>
<li>hosts文件变得非常大</li>
<li>主机名字会冲突</li>
<li>集中的维护站点会不堪重负</li>
</ul>
</blockquote>
<ul>
<li>域名结构</li>
</ul>
<p>通常 Internet 主机域名的一般结构为：主机名.三级域名.二级域名.顶级域名。 Internet 的顶级域名由 Internet网络协会域名注册查询负责网络地址分配的委员会进行登记和管理，它还为 Internet的每一台主机分配唯一的 IP 地址。全世界现有三个大的网络信息中心： 位于美国的 Inter-NIC，负责美国及其他地区； 位于荷兰的RIPE-NIC，负责欧洲地区；位于日本的APNIC，负责亚太地区</p>
<ul>
<li>监听的端口</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">53/udp <span class="comment"># 普通查询</span></span><br><span class="line">53/tcp <span class="comment"># 从服务器到主服务器进行数据传输，为保证数据完整性，使用tcp协议</span></span><br><span class="line">953/tcp<span class="comment"># rndc远程域名服务器控制器</span></span><br></pre></td></tr></table></figure>
<ul>
<li>DNS的功能</li>
</ul>
<p>每个IP地址都可以有一个主机名，主机名由一个或多个字符串组成，字符串之间用小数点隔开。有了主机名，就不用死记硬背每台IP设备的IP地址，只要记住相对直观有意义的主机名就行了。这就是DNS协议所要完成的功能。</p>
<ul>
<li><p>正反解析</p>
<ul>
<li>正向解析：从域名到ip地址的解析过程</li>
<li>反向解析：从ip地址到域名的解析过程，反向解析一般用来进行服务器的身份验证</li>
</ul>
</li>
<li><p>DNS查询</p>
<ul>
<li>查询的优先级<br>本地hosts文件---&gt;本地缓存---&gt;本地DNS区域文件    </li>
<li>分级查询<br>从根域开始，依次查询每一级域名的NS记录，直到查到最终的IP地址。DNS服务器根据域名的层级，进行分级查询。每一级域名都有自己的NS记录，NS记录指向该级域名的域名服务器。这些服务器知道下一级域名的各种记录。</li>
<li>递归查询：客户端向DNS服务器发送一次请求，DNS服务器逐级完成查询完成后直接返回结果。对于客户端来讲为递归查询，对于DNS服务器来讲是迭代查询。<br><img src="http://ohlli9uc9.bkt.clouddn.com/dns1.jpg" alt=""></li>
<li>迭代查询：客户端需要发起多次请求才可得到结果<br><img src="http://ohlli9uc9.bkt.clouddn.com/dns2.jpg" alt=""></li>
</ul>
</li>
</ul>
<blockquote>
<p>默认情况下，DNS服务器使用递归方式来解析域名。递归的含义就是DNS服务器作为DNS客户端向其他DNS服务器查询此解析请求，直到获得解析结果，在此过程中，原客户端则等待DNS服务器的回复。</p>
</blockquote>
<p>参考链接： <a href="http://blog.csdn.net/lycb_gz/article/details/11720247" target="_blank" rel="noopener">http://blog.csdn.net/lycb_gz/article/details/11720247</a></p>
<ul>
<li><p>DNS应答</p>
<ul>
<li>权威应答<br>如果DNS服务器在自己的区域文件里找到了客户端需要查询的记录，就会返回一个权威性应答。如果DNS服务器最近被查找过该主机记录，就会在缓存里找到记录应答客户端。如果找不到主机的A记录，就会返回（RecordNotFound）应答――同样是权威性应答。</li>
<li>非权威应答<br>如果接到DNS查询请求的服务器不是指定域的名称服务器，则：首先查询其他DNS服务器直到找到，然后此服务器将找到的内容返回给客户端――非权威性应答。其次，推荐客户端到上一级DNS服务器找。―――非权威性应答。</li>
</ul>
</li>
<li><p>DNS冗余</p>
</li>
</ul>
<p>为保证服务的高可用性，DNS要求使用多台名称服务器冗余支持每个区域。某个区域的资源记录通过手动或自动方式更新到单个主名称服务器（称为主DNS服务器）上，主 DNS 服务器可以是一个或几个区域的权威名称服务器。</p>
<p>其它冗余名称服务器（称为辅 DNS 服务器）用作同一区域中主服务器的备份服务器，以防主服务器无法访问或宕机。辅 DNS服务器定期与主 DNS 服务器通讯，确保它的区域信息保持最新。如果不是最新信息，辅DNS服务器就会从主服务器获取最新区域数据文件的副本。这种将区域文件复制到多台名称服务器的过程称为区域复制。</p>
<ul>
<li><p>服务器类型</p>
<ul>
<li>主从服务器：主服务器数据修改，辅助服务器请求数据同步</li>
<li>缓存服务器</li>
<li>转发器</li>
</ul>
</li>
<li><p>资源记录</p>
<ul>
<li>为了将名字解析为IP地址，服务器查询它们的区(DNS数据库文件)。区中包含组成相关DNS域资源信息的资源记录（RR）。</li>
<li>某些资源记录不仅包括DNS域中服务器的信息，还可以用于定义域，即指定每台服务器授权了哪些域，这些资源记录就是SOA和NS资源记录。</li>
<li>数据库中的每一个条目称作是一个资源记录(Resource Record，RR)，它是一个五元组，可以用以下格式表示：</li>
</ul>
</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">Domain_name Time_to_live Class Type Value</span><br><span class="line"><span class="comment">#</span></span><br><span class="line"><span class="comment"># Domain_name	指出这条记录适用于哪个域名</span></span><br><span class="line"><span class="comment"># Time_to_live	用来表明记录的生存周期，也就是说最多可以缓存该记录多长时间，可省略</span></span><br><span class="line"><span class="comment"># Class	一般总是IN；对应的是internet</span></span><br><span class="line"><span class="comment"># Type	资源记录的类型</span></span><br><span class="line"><span class="comment"># Value	记录的值，如果是A记录，则value是一个IPv4地址</span></span><br></pre></td></tr></table></figure>
<table>
<thead>
<tr>
<th>名称</th>
<th>TTL值(可选)</th>
<th>Internet</th>
<th>资源记录类型</th>
<th>值</th>
</tr>
</thead>
<tbody>
<tr>
<td>NAME</td>
<td>TTL</td>
<td>IN</td>
<td>RRT</td>
<td>VALUE</td>
</tr>
<tr>
<td>www.nettest.net</td>
<td>600</td>
<td>IN</td>
<td>A</td>
<td>161.202.43.78</td>
</tr>
<tr>
<td>161.202.43.78</td>
<td>600</td>
<td>IN</td>
<td>PTR</td>
<td>www.nettest.net</td>
</tr>
</tbody>
</table>
<ul>
<li>资源记录及类型</li>
</ul>
<h5 id="Bind安装配置"><a href="#Bind安装配置" class="headerlink" title="Bind安装配置"></a>Bind安装配置</h5><h6 id="Bind"><a href="#Bind" class="headerlink" title="Bind"></a>Bind</h6><ul>
<li>全称是Berkeley Internet Name Domain(伯克利因特网名字域系统)。</li>
<li>官方网址：<a href="http://www.isc.org/" target="_blank" rel="noopener">http://www.isc.org/</a></li>
<li>它主要有3个版本：BIND 4，BIND 8，BIND9。</li>
</ul>
<h6 id="业务需求"><a href="#业务需求" class="headerlink" title="业务需求"></a>业务需求</h6><ul>
<li><p>购买的域名以及IP资源</p>
<blockquote>
<p>netpas.info<br>netpas.co<br>36.110.137.112/28<br>60.12.69.160/27<br>106.38.222.176/28</p>
</blockquote>
<ul>
<li>需求<ul>
<li>主从权威名称服务器<br>ns1.netpas.info 36.110.137.123(虚拟机使用192.168.247.123代替)<br>ns2.netpas.info 60.12.69.164(虚拟机使用192.168.247.164代替)</li>
<li>邮件服务器<br>mail.netpas.co  36.110.137.123</li>
<li>网站服务器<br>www.netpas.co   36.110.137.126</li>
<li>ftp服务器<br>ftp.netpas.co   106.38.222.181</li>
<li>别名<br>www2.netpas.co -&gt; www.netpas.co</li>
</ul>
</li>
</ul>
</li>
</ul>
<h6 id="安装配置"><a href="#安装配置" class="headerlink" title="安装配置"></a>安装配置</h6><ul>
<li>配置yum源，安装bind的rpm包</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">yum list all | grep <span class="string">'^bind'</span></span><br><span class="line">yum -y install <span class="built_in">bind</span></span><br></pre></td></tr></table></figure>
<ul>
<li>文件说明</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">/usr/sbin/named</span><br><span class="line"><span class="comment"># 主程序文件</span></span><br><span class="line">/etc/named.conf</span><br><span class="line"><span class="comment"># 主配置文件</span></span><br><span class="line">options&#123;....&#125;;</span><br><span class="line"><span class="comment"># 全局配置段</span></span><br><span class="line">logging&#123;....&#125;;</span><br><span class="line"><span class="comment"># 日志配置段</span></span><br><span class="line">zone&#123;.....&#125;;</span><br><span class="line"><span class="comment"># 由本机负责解析的区域或转发的区域</span></span><br><span class="line">/var/named/</span><br><span class="line"><span class="comment"># 数据文件目录</span></span><br><span class="line">/var/named/named.ca</span><br><span class="line"><span class="comment"># 存放根域的配置文件</span></span><br></pre></td></tr></table></figure>
<ul>
<li><p>区域配置的语法结构</p>
<ul>
<li><p>区域</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">zone <span class="string">"ZONE NAME"</span> IN &#123;</span><br><span class="line">    <span class="built_in">type</span> &#123;master|slave|hint|forward&#125;;</span><br><span class="line">           ;主    |从   |根  |转发器</span><br><span class="line">    file <span class="string">"区域数据文件"</span>;</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>
</li>
<li><p>主区域</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">file <span class="string">"区域数据文件"</span>;</span><br></pre></td></tr></table></figure>
</li>
<li><p>从区域</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">file <span class="string">"区域数据文件"</span>;</span><br><span class="line">masters &#123; master_ip; &#125;;</span><br></pre></td></tr></table></figure>
</li>
</ul>
</li>
<li><p>在主机192.168.247.123配置named.conf<br>编辑<code>/etc/named.conf</code></p>
</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line">options &#123;</span><br><span class="line">        listen-on &#123; 192.168.247.123;&#125;;</span><br><span class="line">        allow-transfer &#123;<span class="string">"none"</span>;&#125;;</span><br><span class="line">        allow-recursion &#123;<span class="string">"any"</span>;&#125;;</span><br><span class="line">        recursion yes;</span><br><span class="line">        allow-query &#123;any;&#125;;</span><br><span class="line">        max-cache-ttl 900;</span><br><span class="line">        directory <span class="string">"/var/named"</span>;</span><br><span class="line">        pid-file <span class="string">"/var/named/named.pid"</span>;</span><br><span class="line">        dump-file <span class="string">"/var/named/named_dump.db"</span>;</span><br><span class="line">        statistics-file <span class="string">"/var/named/named.status"</span>;</span><br><span class="line">&#125;;</span><br><span class="line">zone <span class="string">"."</span> IN &#123;</span><br><span class="line">        <span class="built_in">type</span> hint;</span><br><span class="line">        file <span class="string">"named.ca"</span>;</span><br><span class="line">&#125;;</span><br><span class="line">zone <span class="string">"localhost"</span> IN &#123;</span><br><span class="line">        <span class="built_in">type</span> master;</span><br><span class="line">        file <span class="string">"named.localhost"</span>;</span><br><span class="line">&#125;;</span><br><span class="line">zone <span class="string">"0.0.127.in-addr.arpa"</span> IN &#123;</span><br><span class="line">        <span class="built_in">type</span> master;</span><br><span class="line">        file <span class="string">"named.loopback"</span>;</span><br><span class="line">&#125;;</span><br><span class="line">zone <span class="string">"netpas.info"</span> IN &#123;</span><br><span class="line">        <span class="built_in">type</span> master;</span><br><span class="line">        file <span class="string">"zone.netpas.info"</span>;</span><br><span class="line">&#125;;</span><br><span class="line">zone <span class="string">"netpas.co"</span> IN &#123;</span><br><span class="line">        <span class="built_in">type</span> master;</span><br><span class="line">        file <span class="string">"zone.netpas.co"</span>;</span><br><span class="line">&#125;;</span><br><span class="line">zone <span class="string">"137.110.36.in-addr.arpa"</span> IN &#123;</span><br><span class="line">        <span class="built_in">type</span> master;</span><br><span class="line">        file <span class="string">"zone.36.110.137"</span>;</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>
<ul>
<li>修改语法，检查配置，启动服务</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">chown root:named /etc/named.conf</span><br><span class="line">named-checkconf</span><br><span class="line">named-checkzone <span class="string">"localhost"</span> /var/named/named.localhost </span><br><span class="line">named-checkzone <span class="string">"0.0.127.in-addr.arpa"</span> /var/named/named.loopback </span><br><span class="line">setenforce disabled</span><br><span class="line">/bin/sed -ri <span class="string">'s/(^SELINUX=).*/\1disabled/'</span> /etc/selinux/config</span><br><span class="line">/usr/sbin/named -u root -c /etc/named.conf </span><br><span class="line"><span class="built_in">echo</span> <span class="string">"/usr/sbin/named -u root -c /etc/named.conf"</span> &gt;&gt; /etc/rc.local</span><br></pre></td></tr></table></figure>
<ul>
<li>修改本地DNS，进行测试</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sed -ri <span class="string">'s#^(nameserver).*#\1 192.168.247.123#'</span> /etc/resolv.conf</span><br></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">dig -t NS . @192.168.247.123 +short  <span class="comment"># 确保网络畅通</span></span><br><span class="line">c.root-servers.net.</span><br><span class="line">g.root-servers.net.</span><br><span class="line">l.root-servers.net.</span><br><span class="line">f.root-servers.net.</span><br><span class="line">m.root-servers.net.</span><br><span class="line">e.root-servers.net.</span><br><span class="line">j.root-servers.net.</span><br><span class="line">a.root-servers.net.</span><br><span class="line">k.root-servers.net.</span><br><span class="line">i.root-servers.net.</span><br><span class="line">b.root-servers.net.</span><br><span class="line">h.root-servers.net.</span><br><span class="line">d.root-servers.net.</span><br></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">dig @192.168.247.123 www.baidu.com +short</span><br><span class="line">www.a.shifen.com.</span><br><span class="line">61.135.169.125</span><br><span class="line">61.135.169.121</span><br></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">ping www.baidu.com -c 2</span><br><span class="line">PING www.a.shifen.com (61.135.169.121) 56(84) bytes of data.</span><br><span class="line">64 bytes from 61.135.169.121: icmp_seq=1 ttl=56 time=7.63 ms</span><br><span class="line">64 bytes from 61.135.169.121: icmp_seq=2 ttl=56 time=7.56 ms</span><br><span class="line">--- www.a.shifen.com ping statistics ---</span><br><span class="line">2 packets transmitted, 2 received, 0% packet loss, time 1008ms</span><br><span class="line">rtt min/avg/max/mdev = 7.566/7.599/7.633/0.093 ms</span><br></pre></td></tr></table></figure>
<ul>
<li>区域文件<code>/var/named/zone.netpas.info</code></li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable">$TTL</span> 600</span><br><span class="line">@       IN      SOA     @   memory.netpas.co. (</span><br><span class="line">                                2006103002  ; Serial at current time</span><br><span class="line">                                1D            ; Refresh after 1 day</span><br><span class="line">                                1H            ; Retry after 1 houre</span><br><span class="line">                                1M            ; Expire after 1 month</span><br><span class="line">                                1W)           ; Minimum TTL of 1 week</span><br><span class="line">netpas.info.  IN  NS    ns1.netpas.info.</span><br><span class="line">@               IN  NS    ns2                ; 区域名称可省略，自动补全</span><br><span class="line">ns1             IN  A     192.168.247.123</span><br><span class="line">ns2             IN  A     192.168.247.164</span><br></pre></td></tr></table></figure>
<ul>
<li>区域文件<code>/var/named/zone.netpas.co</code></li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable">$TTL</span> 600</span><br><span class="line">@       IN      SOA     @   memory.netpas.co. (</span><br><span class="line">                        2010111004	;Serial at current time</span><br><span class="line">                        86400		;Refresh after 1 day</span><br><span class="line">                        3600        ;Retry after 1 houre</span><br><span class="line">                        2419200	;Expire after 1 month</span><br><span class="line">                        60480       ;Minimum TTL of 1 week</span><br><span class="line">)</span><br><span class="line">@       IN      NS      ns1.netpas.info.</span><br><span class="line">@       IN      NS      ns2.netpas.info.</span><br><span class="line">@       IN      MX 10   mail.netpas.co.</span><br><span class="line">www     IN      A       36.110.137.126</span><br><span class="line">www2    IN      CNAME   www</span><br><span class="line">ftp     IN      A       36.110.137.181</span><br><span class="line">mail    IN      A       36.110.137.123</span><br><span class="line">*       IN      A       36.110.137.126  ;*代表所有，即*.netpas.co</span><br></pre></td></tr></table></figure>
<ul>
<li>对区域进行检查和文件权限，属主属组的修改；重读配置文件进行测试</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">chmod 640 /var/named/zone.netpas.*</span><br><span class="line">chown root:named /var/named/zone.netpas.*</span><br></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">named-checkzone <span class="string">"netpas.co"</span> /var/named/zone.netpas.co </span><br><span class="line">named-checkzone <span class="string">"netpas.info"</span> /var/named/zone.netpas.info</span><br><span class="line">pkill -1 named</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">dig @192.168.247.123 -t NS netpas.co</span><br><span class="line">dig @192.168.247.123 -t A ftp.netpas.co</span><br><span class="line">dig @192.168.247.123 -t A ns1.netpas.info</span><br><span class="line">dig @192.168.247.123 -t MX netpas.co </span><br><span class="line">dig -x 36.110.137.123</span><br></pre></td></tr></table></figure>
<h4 id="主从复制及区域传送"><a href="#主从复制及区域传送" class="headerlink" title="主从复制及区域传送"></a>主从复制及区域传送</h4><h5 id="Bind配置"><a href="#Bind配置" class="headerlink" title="Bind配置"></a>Bind配置</h5><p>从服务器（slave）192.168.247.164 bind配置，配置完成后进行主、从DNS日期时间同步</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">setenforce disabled</span><br><span class="line">sed -ri <span class="string">'s/(^SELINUX=).*/\1disabled/'</span> /etc/selinux/config</span><br><span class="line">yum list all | grep <span class="string">'^bind'</span></span><br><span class="line">yum -y install <span class="built_in">bind</span></span><br><span class="line">chown -R named:named /var/named/   </span><br><span class="line">chmod 770 /var/named/ </span><br><span class="line"><span class="built_in">cd</span> /etc/ ; mv named.conf&#123;,.orig&#125;</span><br><span class="line">scp -p 2828 root@192.168.247.123:/etc/named.conf ./  </span><br><span class="line">chown root:named /etc/named.conf</span><br></pre></td></tr></table></figure>
<h5 id="主配置文件配置"><a href="#主配置文件配置" class="headerlink" title="主配置文件配置"></a>主配置文件配置</h5><p>生成区域文件的工具: <a href="http://pgl.yoyo.org/adservers/bind-zone-file-creator.php" target="_blank" rel="noopener">http://pgl.yoyo.org/adservers/bind-zone-file-creator.php</a></p>
<h6 id="主DNS-etc-named-conf"><a href="#主DNS-etc-named-conf" class="headerlink" title="主DNS (/etc/named.conf)"></a>主DNS (<code>/etc/named.conf</code>)</h6><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line">options &#123;</span><br><span class="line">        listen-on &#123;192.168.247.123;&#125;;</span><br><span class="line">        allow-transfer &#123;<span class="string">"none"</span>;&#125;;</span><br><span class="line">        allow-recursion &#123;<span class="string">"any"</span>;&#125;;</span><br><span class="line">        recursion yes;</span><br><span class="line">        notify yes;;启用通知从服务器同步功能</span><br><span class="line">        allow-query &#123;any;&#125;;</span><br><span class="line">        max-cache-ttl 900;</span><br><span class="line">        directory <span class="string">"/var/named"</span>;</span><br><span class="line">        pid-file <span class="string">"/var/named/named.pid"</span>;</span><br><span class="line">        dump-file <span class="string">"/var/named/named_dump.db"</span>;</span><br><span class="line">        statistics-file <span class="string">"/var/named/named.status"</span>;</span><br><span class="line">zone <span class="string">"localhost"</span> IN &#123;</span><br><span class="line">        <span class="built_in">type</span> master;</span><br><span class="line">        file <span class="string">"named.localhost"</span>;</span><br><span class="line">        allow-transfer &#123;none;&#125;;</span><br><span class="line">&#125;;</span><br><span class="line">zone <span class="string">"0.0.127.in-addr.arpa"</span> IN &#123;</span><br><span class="line">        <span class="built_in">type</span> master;</span><br><span class="line">        file <span class="string">"named.loopback"</span>;</span><br><span class="line">        allow-transfer &#123;none;&#125;;</span><br><span class="line">&#125;;</span><br><span class="line">zone <span class="string">"netpas.info"</span> IN &#123;</span><br><span class="line">        <span class="built_in">type</span> master;</span><br><span class="line">        file <span class="string">"zone.netpas.info"</span>;</span><br><span class="line">        allow-transfer &#123;192.168.247.164;&#125;;</span><br><span class="line">&#125;;</span><br><span class="line">zone <span class="string">"netpas.co"</span> IN &#123;</span><br><span class="line">        <span class="built_in">type</span> master;</span><br><span class="line">        file <span class="string">"zone.netpas.co"</span>;</span><br><span class="line">        allow-transfer &#123;192.168.247.164;&#125;;</span><br><span class="line">&#125;;</span><br><span class="line">zone <span class="string">"137.110.36.in-addr.arpa"</span> IN &#123;</span><br><span class="line">        <span class="built_in">type</span> master;</span><br><span class="line">        file <span class="string">"zone.36.110.137"</span>;</span><br><span class="line">        allow-transfer &#123;192.168.247.164;&#125;;</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>
<h6 id="从DNS-etc-named-conf"><a href="#从DNS-etc-named-conf" class="headerlink" title="从DNS (/etc/named.conf)"></a>从DNS (<code>/etc/named.conf</code>)</h6><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">options &#123;</span><br><span class="line">        listen-on &#123;192.168.247.164;&#125;;</span><br><span class="line">        allow-transfer &#123;<span class="string">"none"</span>;&#125;;</span><br><span class="line">        allow-recursion &#123;<span class="string">"any"</span>;&#125;;</span><br><span class="line">        recursion yes;</span><br><span class="line">        allow-query &#123;any;&#125;;</span><br><span class="line">        max-cache-ttl 900;</span><br><span class="line">        directory <span class="string">"/var/named"</span>;</span><br><span class="line">        pid-file <span class="string">"/var/named/named.pid"</span>;</span><br><span class="line">        dump-file <span class="string">"/var/named/named_dump.db"</span>;</span><br><span class="line">        statistics-file <span class="string">"/var/named/named.status"</span>;</span><br><span class="line">        masterfile-format text; ;以防出现乱码</span><br><span class="line">&#125;;</span><br><span class="line">zone <span class="string">"."</span> IN &#123;</span><br><span class="line">        <span class="built_in">type</span> hint;</span><br><span class="line">        file <span class="string">"named.ca"</span>;</span><br><span class="line">&#125;;</span><br><span class="line">zone <span class="string">"netpas.info"</span> IN &#123;</span><br><span class="line">        <span class="built_in">type</span> slave; ;类型为从服务器</span><br><span class="line">        masters &#123; 192.168.247.123; &#125;; ;定义主服务器</span><br><span class="line">        file <span class="string">"zone.netpas.info"</span>;</span><br><span class="line">&#125;;</span><br><span class="line">zone <span class="string">"netpas.co"</span> IN &#123;</span><br><span class="line">        <span class="built_in">type</span> slave;</span><br><span class="line">        masters &#123; 192.168.247.123; &#125;;</span><br><span class="line">        file <span class="string">"zone.netpas.co"</span>;</span><br><span class="line">&#125;;</span><br><span class="line">zone <span class="string">"137.110.36.in-addr.arpa"</span> IN &#123;</span><br><span class="line">        <span class="built_in">type</span> slave;</span><br><span class="line">        masters &#123; 192.168.247.123; &#125;;</span><br><span class="line">        file <span class="string">"zone.36.110.137"</span>;</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>
<h5 id="区域传送测试"><a href="#区域传送测试" class="headerlink" title="区域传送测试"></a>区域传送测试</h5><ul>
<li>重启进程</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">pkill -9 named;/usr/sbin/named -u named -c /etc/named.conf</span><br><span class="line">pkill -9 named;/usr/sbin/named -u named -c /etc/named.conf</span><br></pre></td></tr></table></figure>
<ul>
<li><p>查看日志<br>此处以私网地址模拟公网实际情况</p>
<ul>
<li>主(<code>tail /var/log/messages</code>)<br><img src="http://ohlli9uc9.bkt.clouddn.com/dns3.png" alt=""></li>
<li>辅(<code>tail /var/log/messages</code>)<br><img src="http://ohlli9uc9.bkt.clouddn.com/dns4.png" alt=""></li>
</ul>
</li>
<li><p>从服务器更新测试</p>
<ul>
<li>修改主服务器区域文件，添加一条NS记录并修改序列号<br><img src="http://ohlli9uc9.bkt.clouddn.com/dns5.png" alt=""></li>
<li>主服务器重启进程，测试从服务器是否正常同步<br><img src="http://ohlli9uc9.bkt.clouddn.com/dns6.png" alt=""></li>
</ul>
</li>
</ul>
<h5 id="rndc远程控制"><a href="#rndc远程控制" class="headerlink" title="rndc远程控制"></a>rndc远程控制</h5><ul>
<li>在主DNS生成rndc.conf配置文件</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">rndc-confgen -s 127.0.0.1  -r /dev/urandom &gt; /etc/rndc.conf</span><br><span class="line">chown named:named /etc/rndc.conf</span><br></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">cat /etc/rndc.conf </span><br><span class="line"><span class="comment"># Start of rndc.conf</span></span><br><span class="line">key <span class="string">"rndc-key"</span> &#123;</span><br><span class="line">        algorithm hmac-md5;</span><br><span class="line">        secret <span class="string">"01w5DHWUh7M4C+klEDKUjg=="</span>;</span><br><span class="line">&#125;;</span><br><span class="line">options &#123;</span><br><span class="line">        default-key <span class="string">"rndc-key"</span>;</span><br><span class="line">        default-server 127.0.0.1;</span><br><span class="line">        default-port 953;</span><br><span class="line">&#125;;</span><br><span class="line"><span class="comment"># End of rndc.conf</span></span><br><span class="line"><span class="comment"># Use with the following in named.conf, adjusting the allow list as needed:</span></span><br><span class="line"><span class="comment"># key "rndc-key" &#123;</span></span><br><span class="line"><span class="comment">#       algorithm hmac-md5;</span></span><br><span class="line"><span class="comment">#       secret "01w5DHWUh7M4C+klEDKUjg==";</span></span><br><span class="line"><span class="comment"># &#125;;</span></span><br><span class="line"><span class="comment"># </span></span><br><span class="line"><span class="comment"># controls &#123;</span></span><br><span class="line"><span class="comment">#       inet 127.0.0.1 port 953</span></span><br><span class="line"><span class="comment">#               allow &#123; 127.0.0.1; &#125; keys &#123; "rndc-key"; &#125;;</span></span><br><span class="line"><span class="comment"># &#125;;</span></span><br><span class="line"><span class="comment"># End of named.conf</span></span><br></pre></td></tr></table></figure>
<p>将开头的”key”节覆盖到/etc/rndc.key</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># Start of rndc.conf</span></span><br><span class="line">key <span class="string">"rndc-key"</span> &#123;</span><br><span class="line">        algorithm hmac-md5;</span><br><span class="line">        secret <span class="string">"01w5DHWUh7M4C+klEDKUjg=="</span>;</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>
<p>将#开头的行写到<code>/etc/named.conf</code>文件中，并修改</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">key <span class="string">"rndc-key"</span> &#123;</span><br><span class="line">        algorithm hmac-md5;</span><br><span class="line">        secret <span class="string">"01w5DHWUh7M4C+klEDKUjg=="</span>;</span><br><span class="line">&#125;;</span><br><span class="line">controls &#123;</span><br><span class="line">        inet 192.168.247.123 port 953</span><br><span class="line">                allow &#123; any; &#125; keys &#123; <span class="string">"rndc-key"</span>; &#125;;</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>
<p>修改<code>/etc/rndc.conf</code></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># Start of rndc.conf</span></span><br><span class="line">key <span class="string">"rndc-key"</span> &#123;</span><br><span class="line">        algorithm hmac-md5;</span><br><span class="line">        secret <span class="string">"01w5DHWUh7M4C+klEDKUjg=="</span>;</span><br><span class="line">&#125;;</span><br><span class="line">options &#123;</span><br><span class="line">        default-key <span class="string">"rndc-key"</span>;</span><br><span class="line">        default-server 192.168.247.123;</span><br><span class="line">        default-port 953;</span><br><span class="line">&#125;;</span><br><span class="line"><span class="comment"># End of rndc.conf</span></span><br></pre></td></tr></table></figure>
<ul>
<li>命令测试</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">rndc -c /etc/rndc.conf status   </span><br><span class="line">rndc -c /etc/rndc.conf notify <span class="string">"xingxing.com"</span> <span class="comment"># 手动通知区域</span></span><br><span class="line">rndc -c /etc/rndc.conf flush <span class="comment"># 清空缓存</span></span><br><span class="line">rndc -c /etc/rndc.conf stop <span class="comment"># 停止dns服务</span></span><br></pre></td></tr></table></figure>
<ul>
<li>从DNS（slave dns server ）远程控制本机</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">scp -P 22 /etc/rndc.conf 192.168.247.164:/root/</span><br><span class="line">rndc -c /root/rndc.conf status</span><br></pre></td></tr></table></figure>
<h4 id="子域授权"><a href="#子域授权" class="headerlink" title="子域授权"></a>子域授权</h4><ul>
<li><p>应用场景<br>子域授权，在原有的域上再划分出一个小的区域并指定新DNS服务器。在这个小的区域中如果有客户端请求解析，则只要找新的子DNS服务器。这样的做的好处可以减轻主DNS的压力，也有利于管理。这里只做正向区域的子域授权。</p>
</li>
<li><p>文件配置<br>以子域m.netpas.co.为例</p>
<ul>
<li><p>主DNS配置<br>在主DNS的<code>/var/named/zone.netpas.co</code>添加子域资源记录并修改序列号，重新加载进程完成主从同步</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">m       IN      NS      ns1.m.netpas.co.</span><br><span class="line">ns1.m   IN      A       192.168.247.68</span><br></pre></td></tr></table></figure>
</li>
<li><p>子域服务器配置<br>在子域<code>m.netpas.co.</code>服务器进行相关配置，启动服务</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># /etc/named.conf</span></span><br><span class="line">options &#123;</span><br><span class="line">        listen-on &#123;192.168.247.68;&#125;;</span><br><span class="line">        recursion yes;</span><br><span class="line">        allow-query &#123;any;&#125;;</span><br><span class="line">        directory <span class="string">"/var/named"</span>;</span><br><span class="line">&#125;;</span><br><span class="line">zone <span class="string">"m.netpas.co"</span> IN &#123;</span><br><span class="line">        <span class="built_in">type</span> master;</span><br><span class="line">        file <span class="string">"zone.m.netpas.co"</span>;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="comment"># /var/named/zone.m.netpas.co</span></span><br><span class="line"><span class="variable">$TTL</span> 600</span><br><span class="line">@    IN  SOA   @   memory.netpas.co. (</span><br><span class="line">                                2006103001; Serial at current time</span><br><span class="line">                                1D        ; Refresh after 1 day</span><br><span class="line">                                1H        ; Retry after 1 houre</span><br><span class="line">                                1M        ; Expire after 1 month</span><br><span class="line">                                1W)       ; Minimum TTL of 1 week</span><br><span class="line"></span><br><span class="line">@                IN  NS    ns1</span><br><span class="line">ns1              IN  A     192.168.247.68</span><br><span class="line">www              IN  A     192.168.247.69</span><br></pre></td></tr></table></figure>
</li>
<li><p>主DNS测试</p>
</li>
</ul>
</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">dig -t ns m.netpas.co </span><br><span class="line">dig  www.m.netpas.co</span><br></pre></td></tr></table></figure>
<ul>
<li>子域DNS测试</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">dig @192.168.247.68 www.netpas.co</span><br><span class="line"><span class="comment"># 无法获取正常结果，需要向父域转发</span></span><br></pre></td></tr></table></figure>
<h4 id="转发器"><a href="#转发器" class="headerlink" title="转发器"></a>转发器</h4><p>在DNS服务器的配置中，如果采用默认的配置，其实效率是较低的，因为默认情况下，我们所有的非权威解析都会被发送到根服务器进行迭代查询。如果采用转发，如将我们的DNS解析请求转发到一些公共DNS服务器上，由于公共DNS服务器上缓存了大量的解析，因此能较原始的迭代查询快。全局转发：作用：实现对非权威解析（已缓存的除外）都转发到特定DNS服务器配置办法</p>
<ul>
<li>配置参数说明</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">forward &#123; only | first &#125;</span><br><span class="line">    ;only 先转发到转发器，如果得不到答案自己不会尝试解析</span><br><span class="line">    ;first 先转发到转发器，如果得不到答案则向根发起请求</span><br></pre></td></tr></table></figure>
<ul>
<li>子域DNS服务器配置文件</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 在子域DNS服务器的`/etc/named.conf`加入以下两行</span></span><br><span class="line">        forward first; </span><br><span class="line">        forwarders &#123; 192.168.247.123; &#125;;</span><br><span class="line"><span class="comment"># 如果仅设置“forwarders”，则在无法联系转发器时，就会尝试自己解析，即转发到根服务器迭代查询实现解析（如果配置有根zone）。</span></span><br><span class="line"><span class="comment"># 如果想服务器在联系不到转发器时不进行多余操作，则可以加上“forward only; ”；这样如果联系不上转发器时，服务器将只查询权威解析和本地缓存的解析。 </span></span><br><span class="line"><span class="comment"># 区域转发：从BIND9.1开始，引入一个新特新：转发区（forward zone ），及允许查询特定区域时，将其转发到指定DNS服务器上。</span></span><br></pre></td></tr></table></figure>
<ul>
<li>测试</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 重启服务，测试</span></span><br><span class="line">dig @192.168.247.68 www.netpas.co</span><br></pre></td></tr></table></figure>
<h4 id="DNS视图"><a href="#DNS视图" class="headerlink" title="DNS视图"></a>DNS视图</h4><ul>
<li><p>智能DNS<br>智能DNS是域名服务在业界首创的智能解析服务。能自动判断访问者的IP地址并解析出对应的IP地址，使网通用户会访问到网通服务器，电信用户会访问到电信服务器。</p>
</li>
<li><p>ACL 和 VIEW</p>
<ul>
<li><p>ACL的应用与配置<br>在named.conf的全局配置中，有如下这样的一行定义允许为那些客户端进行递归查询：<br><code>allow-query { 192.168.8.0/24; };</code><br>这里只允许了这一个IP段，如果是大型企业或者公网我们需要允许的客户端有上百个IP段时，这里会写很长而且如果在多个地方需要用到，则需写多次，配置麻烦且影响查看。因此引入ACL，可以实现集中定义，所有位置均可引用。ACL类似程序开发中的函数。例如:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">acl trust &#123;</span><br><span class="line">    172.16.100.0/24；</span><br><span class="line">    10.35.0.0/24；</span><br><span class="line">    192.168.0.0/24；</span><br><span class="line">    127.0.0.1；</span><br><span class="line">&#125;;</span><br><span class="line">options &#123;</span><br><span class="line">    allow-query &#123; trust; &#125;;   ;引用上面定义的ACL</span><br><span class="line">……其他配置省略……</span><br><span class="line">&#125;;`</span><br></pre></td></tr></table></figure>
</li>
<li><p>视图view<br>view将不同IP地址段发来的查询响应到不同的DNS解析。例如需要对多个不同IP地址段进行配置，就需要明确这些IP地址段，这样View功能才会有效。注意，一旦使用view，所有域都必须定义在view。</p>
</li>
</ul>
</li>
<li><p>使用bind实现智能DNS</p>
<ul>
<li><p>需求说明</p>
<ul>
<li>创建tel_ip、cnc_ip、cm_ip、crc_ip、edu、other 6个访问控制列表表示不同来源(电信，联通，移动，铁通，教育，其他，默认)，以区域netpas.cc和netpas.co为例，实现智能DNS</li>
<li>由于IP地址段数量较大，因此在<code>/var/named/</code>目录下创建目录acl存放不同来源的IP段 </li>
</ul>
</li>
<li><p>配置步骤</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">mkdir -pv /var/named/acl</span><br><span class="line"><span class="built_in">cd</span> /var/named/acl</span><br><span class="line">chown -R named:named /var/named/acl/ </span><br><span class="line">touch &#123;tel,cnc,cm,crc,edu,other&#125;_ip</span><br></pre></td></tr></table></figure>
<p>分别在不同文件创建对应的acl，以下为范例：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># tel_ip </span></span><br><span class="line">acl tel_ip&#123;</span><br><span class="line">         1.0.1.0/24;</span><br><span class="line">         223.255.252.0/23;</span><br><span class="line">&#125;;</span><br><span class="line"><span class="comment"># cnc_ip </span></span><br><span class="line">acl cnc_ip&#123;</span><br><span class="line">         1.24.0.0/13;</span><br><span class="line">         223.166.0.0/15;</span><br><span class="line">&#125;;</span><br><span class="line"><span class="comment"># 以上地址段只写了两个,实际情况需要写上百条,每个地址段占用一行,以分号结尾</span></span><br></pre></td></tr></table></figure>
</li>
</ul>
<p>在<code>/etc/named.conf</code>中添加视图配置以及对acl文件进行include包含</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br></pre></td><td class="code"><pre><span class="line">  options &#123;</span><br><span class="line">        listen-on &#123;192.168.247.123;&#125;;</span><br><span class="line">        allow-transfer &#123;<span class="string">"none"</span>;&#125;;</span><br><span class="line">        allow-recursion &#123;<span class="string">"any"</span>;&#125;;</span><br><span class="line">        recursion yes;</span><br><span class="line">        allow-query &#123;any;&#125;;</span><br><span class="line">        max-cache-ttl 900;</span><br><span class="line">        directory <span class="string">"/var/named"</span>;</span><br><span class="line">        pid-file <span class="string">"/var/named/named.pid"</span>;</span><br><span class="line">        dump-file <span class="string">"/var/named/named_dump.db"</span>;</span><br><span class="line">        statistics-file <span class="string">"/var/named/named.status"</span>;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line">view <span class="string">"tel"</span> &#123;</span><br><span class="line">        match-clients &#123; tel_ip;&#125;;</span><br><span class="line"></span><br><span class="line">        zone <span class="string">"netpas.info"</span> <span class="keyword">in</span> &#123;</span><br><span class="line">               <span class="built_in">type</span> master;</span><br><span class="line">                file <span class="string">"zone.netpas.info"</span>;</span><br><span class="line">                allow-update&#123;none;&#125;;</span><br><span class="line">        &#125;;</span><br><span class="line"></span><br><span class="line">        zone <span class="string">"netpas.co"</span> <span class="keyword">in</span> &#123;</span><br><span class="line">                <span class="built_in">type</span> master;</span><br><span class="line">                file <span class="string">"zone.netpas.co.tel"</span>;</span><br><span class="line">                allow-update&#123;none;&#125;;</span><br><span class="line">        &#125;;</span><br><span class="line"></span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line">view <span class="string">"cnc"</span> &#123;</span><br><span class="line">        match-clients &#123; cnc_ip; &#125;;</span><br><span class="line"></span><br><span class="line">        zone <span class="string">"netpas.info"</span> <span class="keyword">in</span> &#123;</span><br><span class="line">               <span class="built_in">type</span> master;</span><br><span class="line">                file <span class="string">"zone.netpas.info"</span>;</span><br><span class="line">                allow-update&#123;none;&#125;;</span><br><span class="line">        &#125;;</span><br><span class="line"></span><br><span class="line">        zone <span class="string">"netpas.co"</span> <span class="keyword">in</span> &#123;</span><br><span class="line">                <span class="built_in">type</span> master;</span><br><span class="line">                file <span class="string">"zone.netpas.co.cnc"</span>;</span><br><span class="line">                allow-update&#123;none;&#125;;</span><br><span class="line">        &#125;;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line">view <span class="string">"cm"</span> &#123;</span><br><span class="line">        match-clients &#123; cm_ip; &#125;;</span><br><span class="line"></span><br><span class="line">        zone <span class="string">"netpas.info"</span> <span class="keyword">in</span> &#123;</span><br><span class="line">               <span class="built_in">type</span> master;</span><br><span class="line">                file <span class="string">"zone.netpas.info"</span>;</span><br><span class="line">                allow-update&#123;none;&#125;;</span><br><span class="line">        &#125;;</span><br><span class="line">        zone <span class="string">"netpas.co"</span> <span class="keyword">in</span> &#123;</span><br><span class="line">                <span class="built_in">type</span> master;</span><br><span class="line">                file <span class="string">"zone.netpas.co.tel"</span>;</span><br><span class="line">                allow-update&#123;none;&#125;;</span><br><span class="line">        &#125;;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line">view <span class="string">"crc"</span> &#123;</span><br><span class="line">        match-clients &#123; crc_ip;&#125;;</span><br><span class="line"></span><br><span class="line">        zone <span class="string">"netpas.info"</span> <span class="keyword">in</span> &#123;</span><br><span class="line">               <span class="built_in">type</span> master;</span><br><span class="line">                file <span class="string">"zone.netpas.info"</span>;</span><br><span class="line">                allow-update&#123;none;&#125;;</span><br><span class="line">        &#125;;</span><br><span class="line"></span><br><span class="line">        zone <span class="string">"netpas.co"</span> <span class="keyword">in</span> &#123;</span><br><span class="line">                <span class="built_in">type</span> master;</span><br><span class="line">                file <span class="string">"zone.netpas.co.crc"</span>;</span><br><span class="line">                allow-update&#123;none;&#125;;</span><br><span class="line">        &#125;;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line">view <span class="string">"edu"</span> &#123;</span><br><span class="line">        match-clients &#123; edu_ip;&#125;;</span><br><span class="line"></span><br><span class="line">        zone <span class="string">"netpas.info"</span> <span class="keyword">in</span> &#123;</span><br><span class="line">               <span class="built_in">type</span> master;</span><br><span class="line">                file <span class="string">"zone.netpas.info"</span>;</span><br><span class="line">                allow-update&#123;none;&#125;;</span><br><span class="line">        &#125;;</span><br><span class="line"></span><br><span class="line">        zone <span class="string">"netpas.co"</span> <span class="keyword">in</span> &#123;</span><br><span class="line">                <span class="built_in">type</span> master;</span><br><span class="line">                file <span class="string">"zone.netpas.co.edu"</span>;</span><br><span class="line">                allow-update&#123;none;&#125;;</span><br><span class="line">        &#125;;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line">view <span class="string">"other"</span> &#123;</span><br><span class="line">        match-clients &#123; other_ip;&#125;;</span><br><span class="line"></span><br><span class="line">        zone <span class="string">"netpas.info"</span> <span class="keyword">in</span> &#123;</span><br><span class="line">               <span class="built_in">type</span> master;</span><br><span class="line">                file <span class="string">"zone.netpas.info"</span>;</span><br><span class="line">                allow-update&#123;none;&#125;;</span><br><span class="line">        &#125;;</span><br><span class="line"></span><br><span class="line">        zone <span class="string">"netpas.co"</span> <span class="keyword">in</span> &#123;</span><br><span class="line">                <span class="built_in">type</span> master;</span><br><span class="line">                file <span class="string">"zone.netpas.co.tel"</span>;</span><br><span class="line">                allow-update&#123;none;&#125;;</span><br><span class="line">        &#125;;</span><br><span class="line">&#125;;</span><br><span class="line">view <span class="string">"default"</span> &#123;</span><br><span class="line">        match-clients &#123;any;</span><br><span class="line">            172.20.32.0/23;</span><br><span class="line">        &#125;;</span><br><span class="line"></span><br><span class="line">        zone <span class="string">"netpas.info"</span> <span class="keyword">in</span> &#123;</span><br><span class="line">               <span class="built_in">type</span> master;</span><br><span class="line">                file <span class="string">"zone.netpas.info"</span>;</span><br><span class="line">                allow-update&#123;none;&#125;;</span><br><span class="line">        &#125;;</span><br><span class="line"></span><br><span class="line">        zone <span class="string">"netpas.co"</span> <span class="keyword">in</span> &#123;</span><br><span class="line">                <span class="built_in">type</span> master;</span><br><span class="line">                file <span class="string">"zone.netpas.co"</span>;</span><br><span class="line">                allow-update&#123;none;&#125;;</span><br><span class="line">        &#125;;</span><br><span class="line"></span><br><span class="line">&#125;;</span><br><span class="line">include <span class="string">"/var/named/acl/tel_ip"</span>;</span><br><span class="line">include <span class="string">"/var/named/acl/cnc_ip"</span>;</span><br><span class="line">include <span class="string">"/var/named/acl/cm_ip"</span>;</span><br><span class="line">include <span class="string">"/var/named/acl/crc_ip"</span>;</span><br><span class="line">include <span class="string">"/var/named/acl/edu_ip"</span>;</span><br><span class="line">include <span class="string">"/var/named/acl/other_ip"</span>;</span><br></pre></td></tr></table></figure>
<p>在/var/named下分别创建对应的区域文件(可拷贝),并将相关记录改成对应运营商的IP</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">named-checkconf </span><br><span class="line">pkill -9 named</span><br><span class="line">/usr/sbin/named -u root -c /etc/named.conf</span><br></pre></td></tr></table></figure>
<ul>
<li>测试<br>使用dig命令在不同环境下进行测试</li>
</ul>
</li>
</ul>
<h4 id="日志"><a href="#日志" class="headerlink" title="日志"></a>日志</h4><ul>
<li>Logging<br>bind中我们可以通过配置logging来记录日志信息，以便以后对服务器的分析及问题的跟踪。logging语句为域名服务器设定了一个多样性的logging选项。它的channel短语对应于输出方式、格式选项和分类级别，它的名称可以与category短语一起定义多样的日志信息。如果打开日志功能可能会降低dns的性能，因此不建议开启日志功能。</li>
<li>开启日志功能<br>只需要在option里面加入一个选项即可。<code>man named.conf</code></li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">options &#123;</span><br><span class="line"></span><br><span class="line">      directory <span class="string">"/var/named"</span>;</span><br><span class="line">        querylog  yes;</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>
<p>之后查看<code>/var/log/messages</code>就能看到日志信息；这样会浪费大量的空间。可以使用catagory日志系统，帮我们定制需要对哪些行为进行日志检测。</p>
<ul>
<li>日志的设置和定义</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">channel通道：作用主要定义日志输出的方式；在定义通道的语句里有哪些子语句：</span><br><span class="line">            通道的名称，即自定义通道的名称，即是什么类别。</span><br><span class="line">            输出方式和路径；</span><br><span class="line">            输出日志的轮转；即日志1，日志2，日志3...;</span><br><span class="line">            输出日志的大小限制；</span><br><span class="line">            输出到syslog</span><br><span class="line">            定义消息的级别：severity critical |err |warning |notice |info |debug  |dynamic</span><br><span class="line">            定义类别的输出：print-category yes or no</span><br><span class="line">            定义等级的输出：print-severity yes or no</span><br><span class="line">            定义时间的输出：print-time yes or no</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">category类别：定义了那些数据需要记录，即在日志里输出那些日志内容。哪一类的类别使用哪个或哪几个已经定义好的通道</span><br><span class="line">            类别的种类：</span><br><span class="line">            default，没有配置的分类使用default的分类日志配置。</span><br><span class="line">            general，许多没有分类的内容都在此分类；</span><br><span class="line">            database，named使用的，用来存储和缓存的内部数据库信息；</span><br><span class="line">            security，接受和拒绝的请求</span><br><span class="line">            config配置文件分析和处理</span><br><span class="line">            resolver DNA解析；</span><br><span class="line">            xfer-in：服务器收到的域传输；</span><br><span class="line">            xfer-out：服务器发送的域传输。</span><br><span class="line">            queries 请求。</span><br></pre></td></tr></table></figure>
<ul>
<li>日志系统<br>bind的日志系统，提供了两个子系统，一个叫做channel，一个叫做category。</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">catagory: 日志源（指的是产生日志的日志源，比如说有的是跟查询有关的，有的是跟区域传送相关的。）所以catagory可以让我们定义日志来源。</span><br><span class="line">    查询</span><br><span class="line">    区域传送；</span><br><span class="line">    可以通过catagory自定义日志来源；</span><br><span class="line">一个catagory，可以存放到多个位置；一个channel只能存放一个catagory。</span><br><span class="line"></span><br><span class="line">channel: 定义日志的日志保存位置；</span><br><span class="line">    syslog：系统日志；使用日志级别的概念。/var/log/messages.</span><br><span class="line">    file: 自定义保存日志信息的文件。</span><br></pre></td></tr></table></figure>
<ul>
<li>默认channel<br>下面是named 提前定义的四个通道，用于指定缺省的日志。</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">channel <span class="string">"default_syslog"</span> &#123;</span><br><span class="line">    syslog daemon; <span class="comment"># 发送给syslog 的daemon facility</span></span><br><span class="line">    severity info; <span class="comment"># 只发送此优先级和更高优先级的信息</span></span><br><span class="line">&#125;;</span><br><span class="line">channel <span class="string">"default_debug"</span> &#123;</span><br><span class="line">    file <span class="string">"named.run"</span>; <span class="comment"># 写入工作目录下的named.run 文件。注意：如果服务器用-f 参数启动，则"named.run"会被stderr 所替换。</span></span><br><span class="line">    severity dynamic; <span class="comment"># 按照服务器当前的debug 级别记录日志</span></span><br><span class="line">&#125;;</span><br><span class="line">channel <span class="string">"default_stderr"</span>&#123;</span><br><span class="line">    stderr; <span class="comment"># 写到stderr</span></span><br><span class="line">    severity info; <span class="comment"># 只发送此优先级和更高优先级的信息</span></span><br><span class="line">&#125;;</span><br><span class="line">channel <span class="string">"null"</span> &#123;</span><br><span class="line">    null; <span class="comment"># 丢弃所有发到此通道的信息</span></span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>
<p>default_debug 通道有特殊的性质：只有当服务器的debug级别非0的时候，它才产生输出。一般来说，它会在服务器的工作目录中写入named.run文件。因为安全原因，当在命令行选项中使用了“-u”参数后，只有当named使用了新的UID后，named.run文件才会产生，以root身份启动和运行的named所产生的debug信息将会被丢弃。如果用户需要得到这些输出，则必须使用“-g”参数运行服务器，并重新将标准错误定向到一个文件中去。<br>一旦定义好一个通道，它就不能被重新定义。这样就不能修改内置的通道，但是可以通过把分类指向你已经定义的通道，来修改默认的日志记录。</p>
<ul>
<li>示例</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">logging &#123;</span><br><span class="line">    file <span class="string">"log.msgs"</span> version 3 size 10k; <span class="comment">#一旦达到10k，就开始滚动，日志是可以滚动的；</span></span><br><span class="line">    severity dynamic;       <span class="comment">#定义日志级别；</span></span><br><span class="line">    &#125;;</span><br><span class="line">    channel my_syslog &#123;</span><br><span class="line">        syslog local0;        <span class="comment">#定义syslog里面local0的信息存放到哪里去；</span></span><br><span class="line">        severity info;         <span class="comment">#定义local0里面的普通信息放到固定位置去。</span></span><br><span class="line">    &#125;;</span><br><span class="line">    category xfer-in &#123; my_file; &#125;; <span class="comment">#传入   #将传入日志保存到my_file里面去；</span></span><br><span class="line">    category update &#123; my_syslog; &#125;; <span class="comment">#更新信息</span></span><br><span class="line">    &#125;;</span><br></pre></td></tr></table></figure>

      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>有钱任性，请我吃包辣条</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/wechatpay.jpg" alt="孟庆宇 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/alipay.jpg" alt="孟庆宇 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    
      <div>
        <ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者：</strong>
    孟庆宇
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="http://linuxgeeks.github.io/2016/02/05/2016-02-05-123530-DNS服务/" title="DNS服务">http://linuxgeeks.github.io/2016/02/05/2016-02-05-123530-DNS服务/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>
    本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/3.0/" rel="external nofollow" target="_blank">CC BY-NC-SA 3.0</a> 许可协议。转载请注明出处！
  </li>
</ul>

      </div>
    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/DNS/" rel="tag"><i class="fa fa-tag"></i> DNS</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2016/02/04/2016-02-04-141338-OpenSSH/" rel="next" title="OpenSSH">
                <i class="fa fa-chevron-left"></i> OpenSSH
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2016/02/06/2016-02-06-164633-DHCP服务/" rel="prev" title="DHCP Service">
                DHCP Service <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
        
  <div class="bdsharebuttonbox">
    <a href="#" class="bds_tsina" data-cmd="tsina" title="分享到新浪微博"></a>
    <a href="#" class="bds_douban" data-cmd="douban" title="分享到豆瓣网"></a>
    <a href="#" class="bds_sqq" data-cmd="sqq" title="分享到QQ好友"></a>
    <a href="#" class="bds_qzone" data-cmd="qzone" title="分享到QQ空间"></a>
    <a href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信"></a>
    <a href="#" class="bds_tieba" data-cmd="tieba" title="分享到百度贴吧"></a>
    <a href="#" class="bds_twi" data-cmd="twi" title="分享到Twitter"></a>
    <a href="#" class="bds_fbook" data-cmd="fbook" title="分享到Facebook"></a>
    <a href="#" class="bds_more" data-cmd="more"></a>
    <a class="bds_count" data-cmd="count"></a>
  </div>
  <script>
    window._bd_share_config = {
      "common": {
        "bdText": "",
        "bdMini": "2",
        "bdMiniList": false,
        "bdPic": ""
      },
      "share": {
        "bdSize": "16",
        "bdStyle": "0"
      },
      "image": {
        "viewList": ["tsina", "douban", "sqq", "qzone", "weixin", "twi", "fbook"],
        "viewText": "分享到：",
        "viewSize": "16"
      }
    }
  </script>

<script>
  with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='//bdimg.share.baidu.com/static/api/js/share.js?cdnversion='+~(-new Date()/36e5)];
</script>

      
    </div>
  </div>


          </div>
          


          
  


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
      <div id="sidebar-dimmer"></div>
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/avatar.jpg"
                alt="孟庆宇" />
            
              <p class="site-author-name" itemprop="name">孟庆宇</p>
              <p class="site-description motion-element" itemprop="description">书山有路勤为径，学海无涯苦作舟</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">109</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">23</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">56</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          <div class="links-of-author motion-element">
            
              
                <span class="links-of-author-item">
                  <a href="https://github.com/mengdaya" target="_blank" title="GitHub">
                    
                      <i class="fa fa-fw fa-github"></i>GitHub</a>
                </span>
              
                <span class="links-of-author-item">
                  <a href="mailto:yourname@gmail.com" target="_blank" title="E-Mail">
                    
                      <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                </span>
              
            
          </div>

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-inline">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-globe"></i>
                友情链接
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.ibm.com/developerworks/cn/" title="IBM developerWorks" target="_blank">IBM developerWorks</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://iissnan.com/progit/" title="Pro Git" target="_blank">Pro Git</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.freeoa.net/index/" title="freeOA" target="_blank">freeOA</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.ttlsa.com/" title="运维生存时间" target="_blank">运维生存时间</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.361way.com/" title="运维之路" target="_blank">运维之路</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.yiibai.com/" title="易百教程" target="_blank">易百教程</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.centoscn.com/" title="CentOS中文站" target="_blank">CentOS中文站</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.linuxprobe.com/" title="Linux就该这么学" target="_blank">Linux就该这么学</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.netingcn.com/" title="网络进行时" target="_blank">网络进行时</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.ruanyifeng.com/blog/" title="阮一峰的网络日志" target="_blank">阮一峰的网络日志</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.liaoxuefeng.com" title="廖雪峰的官方网站" target="_blank">廖雪峰的官方网站</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://yihui.name/cn/" title="谢益辉的博客" target="_blank">谢益辉的博客</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://coolshell.cn" title="酷壳" target="_blank">酷壳</a>
                  </li>
                
              </ul>
            </div>
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#DNS服务"><span class="nav-number">1.</span> <span class="nav-text">DNS服务</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#DNS基础"><span class="nav-number">1.1.</span> <span class="nav-text">DNS基础</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#Bind安装配置"><span class="nav-number">1.1.1.</span> <span class="nav-text">Bind安装配置</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#Bind"><span class="nav-number">1.1.1.1.</span> <span class="nav-text">Bind</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#业务需求"><span class="nav-number">1.1.1.2.</span> <span class="nav-text">业务需求</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#安装配置"><span class="nav-number">1.1.1.3.</span> <span class="nav-text">安装配置</span></a></li></ol></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#主从复制及区域传送"><span class="nav-number">1.2.</span> <span class="nav-text">主从复制及区域传送</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#Bind配置"><span class="nav-number">1.2.1.</span> <span class="nav-text">Bind配置</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#主配置文件配置"><span class="nav-number">1.2.2.</span> <span class="nav-text">主配置文件配置</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#主DNS-etc-named-conf"><span class="nav-number">1.2.2.1.</span> <span class="nav-text">主DNS (/etc/named.conf)</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#从DNS-etc-named-conf"><span class="nav-number">1.2.2.2.</span> <span class="nav-text">从DNS (/etc/named.conf)</span></a></li></ol></li><li class="nav-item nav-level-5"><a class="nav-link" href="#区域传送测试"><span class="nav-number">1.2.3.</span> <span class="nav-text">区域传送测试</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#rndc远程控制"><span class="nav-number">1.2.4.</span> <span class="nav-text">rndc远程控制</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#子域授权"><span class="nav-number">1.3.</span> <span class="nav-text">子域授权</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#转发器"><span class="nav-number">1.4.</span> <span class="nav-text">转发器</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#DNS视图"><span class="nav-number">1.5.</span> <span class="nav-text">DNS视图</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#日志"><span class="nav-number">1.6.</span> <span class="nav-text">日志</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2015 &mdash; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">文章总结于网络，转载请注明出处</span>

  
</div>









        
<div class="busuanzi-count">
  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user">本站访客</i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      人
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye">本站总访问量</i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      次
    </span>
  
</div>








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>

  
  <script type="text/javascript" src="true"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.3"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.3"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.3"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.3"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.3"></script>



  


  




	





  





  








  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  

  

  

  

</body>
</html>
